﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MedicalLog.Domain.Repositories;
using MedicalLog.Domain.Entities;

namespace MedicalLog.WebUI.Controllers
{
    public class InsuranceController : Controller
    {

        InsuranceRepository repo;

        public InsuranceController()
        {
            repo = new InsuranceRepository();
        }
        //
        // GET: /Insurance/
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult AddInsurance()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AddInsurance(Insurance insurance)
        {
            if (ModelState.IsValid)
            {
                repo.AddInsurance(insurance);
                return RedirectToAction("Detail", new { Id = insurance.IdInsurance });
            }
            else
            {
                return View(insurance);
            }
        }

        public ActionResult Detail(int Id)
        {
            return View(repo.SearchInsurance(Id));
        }

        [HttpGet]
        public ActionResult Edit(int Id)
        {
            return View(repo.DetailInsurance(Id));
        }

        [HttpPost]
        public ActionResult Edit(Insurance insurance)
        {
            if (ModelState.IsValid)
            {
                repo.UpdateInsurance(insurance);
                return RedirectToAction("Detail", new { Id = insurance.IdInsurance });
            }
            else
            {
                return View(insurance);
            }
        }
        
        [HttpGet]
        public ActionResult Delete(int Id)
        {
            return View(repo.DetailInsurance(Id));
        }

        [HttpPost]
        public ActionResult Delete(Insurance insurance)
        {
            repo.DeleteInsurance(insurance.IdInsurance);
            return RedirectToAction("Search", "Patient");
        }
    }
}
